<?php
/**
 * 查看自己的团队,删除了
 */
apf_require_controller("Abstract");
apf_require_class("Bll_Jx_Relation");
apf_require_class("Bll_Jx_Setting");
apf_require_class("Bll_Jx_Plan");
class Grade_ShowMyDepartmentController extends AbstractController {

    public function handle_request() {
        $abc_list = $this->_get_sub_user_score();

        $this->request->set_attribute('abc_list',$abc_list);
        $this->request->set_attribute('user_name',$this->request->get_user_name());
        $this->request->set_attribute('user_id',$this->request->get_user_id());
        return 'Grade_ShowMyDepartment';
    }
    /**
     *
     */
    private function _get_sub_user_score(){
        $setting_bll = new Bll_Jx_Setting();
        $rel_bll = new Bll_Jx_Relation();
        $plan_bll = new Bll_Jx_Plan();
        $last_month = $setting_bll->format_performance();
        $code = $this->request->get_user_code();

        $sub_list = $rel_bll->get_sub_user_list($code);

        if(empty($sub_list)){
            return array();
        }
        //计算人数
        $uids = array();
        if(!empty($sub_list)){
            foreach($sub_list as $val){
                $uids[] = $val['user_id'];
            }
        }
        $_where = array(
                "serachMonth"=>$last_month[0],
                "userId IN(".implode(',',$uids).") AND 1=?"=>1
                );
        $kp_data = $plan_bll->find_performance($_where);
        $abc_list = array('all'=>0);
        $max_users = 0;
        foreach($kp_data as $uid=> $val){
            //上次考核有计划的
                $abc_list['all'] +=1;
                $score = empty($val['adjustScore']) ? $val['personScore'] : $val['adjustScore'];
                $str = Const_JxStatus::check_score_stage($score);
                $abc_list[$str] +=1;
        }
        return $abc_list;
    }
}